<!DOCTYPE html>
<html>
<head>
<title>req_assign</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<link rel="stylesheet" type="text/css"
	href="/codebase/fonts/font_roboto/roboto.css" />
<link rel="stylesheet" type="text/css" href="/codebase/dhtmlx.css" />
<script type="text/javascript" src="/codebase/dhtmlxform.js" />
<script type="text/javascript" src="/codebase/dhtmlxgrid.js" />
<!-- <script type="text/javascript" src="/codebase/dhtmlx.js" /> -->
<style>
</style>
<script>
/*<![CDATA[*/
	var myForm, myGrid, formStructure,myDP;
	function doOnLoad() {
		var v = document.getElementById("assign_req_id").innerHTML;
		//alert("onload req assign");
            if (myForm) {
			myForm.unload();
			myForm = null;
		}
		myForm = new dhtmlXForm("div_count_form");
		//myForm.loadStruct(formStructure);
		myForm.loadStruct("/req/req_modify_detail_workload_info_onload?req_id="
				+ v);

		myForm.attachEvent("onButtonClick", function(name) {
			if (name = "base_info_save_btn") {
				 var g_plan_workload= count_plan_workload();
				 var g_actual_workload=  count_actual_workload();	
				 var g_test_plan_workload=myForm.getItemValue("req_plan_workload");
				 if(g_plan_workload>g_test_plan_workload){
					 alert("计划工作量合计为【"+g_plan_workload+"】，\n应小于需求项目要求的计划工作量【"+g_test_plan_workload+"】, \n请修改录入的相关计划工作量数值");
				 }else{
					 if(g_actual_workload>g_test_plan_workload){
						 alert("实际工作量合计为【"+g_actual_workload+"】，\n应小于需求项目要求的计划工作量【"+g_test_plan_workload+"】, \n请在工作日志中注明延时理由");
					 }
					 //}else{				
						var save_value=prepare_save_data();						
						var count_rows=myGrid.getRowsNum();	
						var count_columns=myGrid.getColumnCount();			
						
						myGrid.clearAndLoad("/req/req_modify_detail_workload_info_save?req_id="+v+"&count_rows="+count_rows+"&count_columns="+count_columns+"&save_info="+save_value,callback,"json");
					// }
				}
			}
		});


		//grid setup
		myGrid = new dhtmlXGridObject("gridbox");
		//myGrid.loadStruct("/common/testmanager/req_list.xml");
		//myGrid.setImagePath("/codebase/imgs/");
		myGrid.setImagePath("/skins/web/imgs/dhxgrid_web/");
		myGrid.setDateFormat("%Y-%m-%d");
		//myGrid.se
		myGrid.setHeader("ID,姓名,角色,计划完成日, 实际完成日,计划工作量,实际工作量");
		myGrid
				.setColumnIds("id,user_name,role,plan_complete_date,actual_complete_date,plan_workload,actual_workload");
		myGrid.setInitWidths("50,100,100,100,100,100,100");
		myGrid.setColAlign("center,left,left,left,left,left,left");
		myGrid.setColTypes("ro,ro,ro,dhxCalendarA,dhxCalendarA,edn,edn");
		var colIndex = myGrid.getColIndexById("plan_workload");
		myGrid.setNumberFormat("0,000.0", colIndex, ".", ",");
		colIndex = myGrid.getColIndexById("actual_workload");
		myGrid.setNumberFormat("0,000.0", colIndex, ".", ",");
		//	myGrid.setColSorting("str,str,str,date,date,str,str");

		myGrid.xml.top = "mytop";
		myGrid.xml.row = "./myrow";
		//myGrid.enableAutoWidth(true);
		//myGrid.enableAutoHeight(true);
		myGrid.init();
		//myDataProcessor = new dataProcessor("/req/req_modify_detail_workload_info_DP"); //lock feed url
		//myDataProcessor.init(myGrid); //link dataprocessor to the grid
	
		//myDP = new dataProcessor("/req/req_modify_detail_workload_info_DP");// initializes dhtmlxDataProcessor
		//myDP.init(myGrid);
		
		myGrid.load("/req/req_modify_detail_workload_info_grid?req_id=" + v,"json");
		
		 
		     
		myGrid.attachEvent("onCellChanged", function(rId,cInd,nValue){
			    if(cInd==5){
			/*	   var g_plan_workload= count_plan_workload();
				   var g_test_plan_workload=myForm.getItemValue("req_plan_workload");
					 if(parseFloat(g_plan_workload)>parseFloat(g_test_plan_workload)){
						 alert("计划工作量合计为【"+g_plan_workload+"】，应小于项目要求的计划工作量【"+g_test_plan_workload+"】, \n 请修改录入的相关计划工作量数值");
					 }else{
                     */
				   		var g_plan_workload= count_plan_workload();
				   		myForm.setItemLabel("count_1", "计划工作量合计  ：     "+g_plan_workload+"    人天   ");
					 }
			   
				if(cInd==6){
				/*	var g_plan=myGrid.cells(rId,5).getValue();
					if(nValue>parseFloat(g_plan)){
						alert("【实际工作量】为"+nValue+",应少于【计划工作量】"+g_plan+"，请在工作日志中注明延时理由");
						var g_actual_workload=  count_actual_workload();	
						 myForm.setItemLabel("count_2",  "实际工作量合计  ：     "+g_actual_workload+"    人天   ");
					}else{*/
						var g_actual_workload=  count_actual_workload();	
						 myForm.setItemLabel("count_2",  "实际工作量合计  ：     "+g_actual_workload+"    人天   ");
					}
			   //}
			});
		   
		/* formStructure = null;
		formStructure = [ {
			type : "label",
			name : "count_1",
			label : "计划工作量合计  ：         人天   ",
			inputWidth : "500"
		}, {
			type : "newcolumn"
		}, {
			type : "label",
			name : "count_1",
			label : "实际工作量合计  ：             人天",
			inputWidth : "500",
			offsetLeft : "50"
		} ]; */
	
	}
	
	var callback=function () {
		//alert("callback");
		
		if(arguments.length==0){
				
		//	myGrid.clearAndLoad("/req/req_modify_detail_workload_info_grid?req_id=" + v,doAfterRefresh,"json");
			alert("保存信息成功");
			
		}
		else{
			alert("保存信息失败，错误信息："+arguments[1]);
		}
	}
	
	
	function prepare_save_data() {
		var tmp="";		
		for (var j=1; j<(myGrid.getRowsNum()+1); j++){	
				for (var i=0; i<myGrid.getColumnCount(); i++){
				//tmp=tmp+j+"_"+i+"=";
				if(i==(myGrid.getColumnCount()-1)){
					tmp=tmp+myGrid.cells(j,i).getValue()+"";	
				}else{
					tmp=tmp+myGrid.cells(j,i).getValue()+",";	
				}
							
			};
			if(j==(myGrid.getRowsNum())){
				tmp=tmp;
			}else{
				tmp=tmp+";";
			}
			
		}
		return tmp;
	}
	
	 function  count_plan_workload(){
		var return_value=0.0;		
		for (var j=1; j<(myGrid.getRowsNum()+1); j++){		
			var tmp=myGrid.cells(j,5).getValue();		
			if(tmp!=""){
				if(isNaN(tmp)==false){
				var x=parseFloat(tmp);
					return_value=return_value + x;
				}
			}
		}
		return return_value;
	}

	function  count_actual_workload(){
		var return_value=0.0;		
		for (var j=1; j<(myGrid.getRowsNum()+1); j++){	
			var tmp=myGrid.cells(j,6).getValue();		
			if(tmp!=""){		
				if(isNaN(tmp)==false){
				var x=parseFloat(tmp);
				return_value=return_value +x;
				}
			}
		}
		return return_value;
	} 
	    
	/*]]>*/
</script>
</head>
<body onload="doOnLoad();">
	<div id="assign_req_id" name="assign_req_id" th:text="${req_id}"
		style="display: none;"></div>	


		<table >
			<tr>
				<td>
					<div id="gridbox" style="width: 700px; height: 200px; background-color: white;"></div>
				</td>
			</tr>
		</table>
	    


	<table>
		<tr>
			<td>
				<div id="form_req_base_info"></div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="div_count_form"></div>
			</td>
		</tr>
	</table>
</body>
</html>